Repository navigation
feat: a command at every lifecycle moment, for teams that write no Python - #39
Closed
AlexeyShalaev wants to merge 1 commit into
Closed
AlexeyShalaev wants to merge 1 commit into
AlexeyShalaev wants to merge 1 commit into
Conversation
…thon A Go or Ruby team already owns an archiver; what they need is for it to be invoked at the right moment with the right metadata. CommandHooks runs a configured command per phase, hands it the PartitionEvent as JSON on stdin, and treats a non-zero exit exactly as a raised exception -- the operation is abandoned and planned again next run. This needed no new hook context. The event has been one model for every phase since the start of this release, so the payload is a dump of the object a Python hook already receives, and before_drop is told the window and the size that DETACH has already erased from the catalog. The commands run only when the run asks for them, and a document declaring hooks is refused rather than quietly stripped when it does not: silently skipping a configured before_drop would let an operator read the file, believe their archiver ran, and be wrong. No sandbox is provided and none is claimed -- the container boundary is the honest answer, and the docs say so. Both mirrors run the command through one blocking implementation, with the aio side handing it to a thread. asyncio.create_subprocess_exec needs a loop that can spawn processes, and a selector loop -- what a Windows asyncpg deployment installs -- raises NotImplementedError instead. A hook that runs in production and not on a developer's machine is a hook nobody trusts.
This was referenced Sep 1, 2026
Member
Author
|
Folded into #43, one PR for the whole epic; this branch stays for history. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3b of #32: hooks as commands.
The epic's stated blocker is already gone. It says #27 must be resolved before 3a/3b so we do not ship a config contract we immediately have to break. Option A shipped in 1.1: one
PartitionEventfor all eight phases. So this needed no new context at all — the payload a command reads isevent.model_dump_json(by_alias=True), the same object a Python hook is handed, andbefore_dropis told the window and the size thatDETACHhas already erased from the catalog.A non-zero exit is a refusal, exactly as a raised exception is; a command outliving its timeout is killed and counts as one, because a hook that hangs holds the table's maintenance lock. Argument vectors only — nothing goes through a shell, so a partition name can never be read as syntax.
On
--allow-hooks. A document declaring hooks is refused rather than quietly stripped when the flag is absent: silently skipping a configuredbefore_dropwould let an operator read the file, believe their archiver ran, and be wrong. The docs make the epic's own argument — the document already authorises dropping tables, so a command in it is not a new privilege boundary as long as it comes from the same trust domain as the DSN, and that stops holding the moment it is assembled from somewhere less trusted. No sandbox is claimed.Two things worth reviewing:
CommandHooksmust implement all eight phase methods — the executor callsgetattr(hook, phase.value)(event)afteron_event, so a hook with onlyon_eventwould abort the operation with anAttributeError. mypy caught it; it now inheritsBasePartitionLifecycleHooks, with a test pinning it.asyncio.create_subprocess_execraisesNotImplementedErroron a selector loop — which is what this repo's own conftest installs on Windows. Rather than patch around the platform, both mirrors run the command through one blocking implementation and the aio side hands it to a thread. A hook that runs in production but not on a developer's machine is a hook nobody trusts.11 unit tests across both mirrors + 3 against a real PostgreSQL, including a hook firing around a real
DROPand a refusing hook leaving the partition in place.